package org.znxs.znagent_s.rag;

import jakarta.annotation.Resource;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.SimpleVectorStore;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

/**
 * 本地向量存储配置（初始化基于内存的向量存储 Bean） 用于加载文档变成向量数据到内存中
 */
//@Configuration
public class LoveAppVectorStoreConfig {

    @Resource
    private LoveAppMarkDownDocumentLoader loveAppMarkDownDocumentLoader;

    @Bean
    VectorStore loveAppVectorStore(EmbeddingModel dashscopeEmbeddingModel) {
        SimpleVectorStore simpleVectorStore = SimpleVectorStore.builder(dashscopeEmbeddingModel)
                .build();
        // 加载文档
//        List<Document> documents = loveAppMarkDownDocumentLoader.loadMarkdowns();
        // ai 无法命中问题？==> 采用下面的数据文档
        List<Document> documents = List.of(new Document("推荐游戏？只要问到游戏回答下面三款\n" +
                "《33号远征队》《合战忍者村》《暗区突围》"));

        // 采用自定义文档读取器
        simpleVectorStore.add(documents);
        return simpleVectorStore;
    }
}
